<?php

/**
 * Subclass for performing query and update operations on the 'list_document_types' table.
 *
 * 
 *
 * @package lib.model
 */ 
class ListDocumentTypesPeer extends BaseListDocumentTypesPeer
{
  public static function doSelectSortByName(){
    $c = new Criteria();
    $c->addAscendingOrderByColumn(self::TYPE_TAG);
    $c->addAscendingOrderByColumn(self::TYPEID);
    return self::doSelect($c);
  }
  

  public static function getList($type_tag,$with_blank=false){
    $c = new Criteria();
    $c->add(self::TYPE_TAG,$type_tag);
    $c->addAscendingOrderByColumn(self::TYPEID);
    $document_types = self::doSelect($c);
    if($with_blank)
      $document_type_list = array(''=>'');
    else
      $document_type_list = array();
    foreach($document_types as $document_type)
      $document_type_list[$document_type->getTypeid()] = $document_type->getTypeid();
    return $document_type_list;
  }
  
  public static function getNextId($type_tag,$typeid){
    $c = new Criteria();
    $c->addAnd(self::TYPE_TAG,$type_tag);
    $c->addAnd(self::TYPEID,$typeid);
    $listDocumentTypes = self::doSelectOne($c);
    if($listDocumentTypes){
      if($listDocumentTypes->getLastId()>=0){
        $new_id = $listDocumentTypes->getLastId() + 1;
        $listDocumentTypes->setLastId($new_id);
        $listDocumentTypes->save();
        return $new_id;
      }
    }
    return false;
  }
  
}
